package Observer.InterfacesImpl;

import Observer.Interfaces.DisplayElement;
import Observer.Interfaces.Observer;
import Observer.Interfaces.Subject;

/**
 * @Author: pengzx
 * @Description:
 * @Date: 16:47 2017/9/5
 * @Modified by: 1.0
 */
public class CurrentConditionDisplay implements Observer,DisplayElement {
    private Subject weatherData;
    private float humidity;
    private float pressure;
    private float temp;
    @Override
    public void display()
    {
        System.out.println("current conditions "+temp+" F degrees and "+humidity+"  % humidity");
    }

    @Override
    public void update(float temp, float humidity, float pressure)
    {
        this.humidity = humidity;
        this.pressure = pressure;
        this.temp = temp;
        display();
    }

    /**
     * 注册一个观察者，并且把主题实例化
     * @param weatherData
     */
    public CurrentConditionDisplay(Subject weatherData)
    {
        this.weatherData = weatherData;
        weatherData.RegisterObserver(this);
    }
}
